<html><head><style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.linenumber {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='linenumber'>  1</span> <span class="COMM">// Copyright 2009 Google Inc. All Rights Reserved.</span><span class="WHIT">
<span class='linenumber'>  2</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='linenumber'>  3</span> </span><span class="COMM">// Licensed under the Apache License, Version 2.0 (the "License");</span><span class="WHIT">
<span class='linenumber'>  4</span> </span><span class="COMM">// you may not use this file except in compliance with the License.</span><span class="WHIT">
<span class='linenumber'>  5</span> </span><span class="COMM">// You may obtain a copy of the License at</span><span class="WHIT">
<span class='linenumber'>  6</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='linenumber'>  7</span> </span><span class="COMM">//      http://www.apache.org/licenses/LICENSE-2.0</span><span class="WHIT">
<span class='linenumber'>  8</span> </span><span class="COMM">//</span><span class="WHIT">
<span class='linenumber'>  9</span> </span><span class="COMM">// Unless required by applicable law or agreed to in writing, software</span><span class="WHIT">
<span class='linenumber'> 10</span> </span><span class="COMM">// distributed under the License is distributed on an "AS-IS" BASIS,</span><span class="WHIT">
<span class='linenumber'> 11</span> </span><span class="COMM">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span><span class="WHIT">
<span class='linenumber'> 12</span> </span><span class="COMM">// See the License for the specific language governing permissions and</span><span class="WHIT">
<span class='linenumber'> 13</span> </span><span class="COMM">// limitations under the License.</span><span class="WHIT">
<span class='linenumber'> 14</span> 
<span class='linenumber'> 15</span> </span><span class="COMM">/**
<span class='linenumber'> 16</span>  * @fileoverview Class which checks a web page for bidi-related errors.
<span class='linenumber'> 17</span>  * This file has the top-level entry points for use as a Javascript API, along
<span class='linenumber'> 18</span>  * with JSON-based interface functions meant to be called from an external
<span class='linenumber'> 19</span>  * testing framework like WebDriver.
<span class='linenumber'> 20</span>  */</span><span class="WHIT">
<span class='linenumber'> 21</span> 
<span class='linenumber'> 22</span> 
<span class='linenumber'> 23</span> </span><span class="NAME">goog.provide</span><span class="PUNC">(</span><span class="STRN">'bidichecker'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 24</span> </span><span class="NAME">goog.provide</span><span class="PUNC">(</span><span class="STRN">'bidichecker.BidiChecker'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 25</span> </span><span class="NAME">goog.provide</span><span class="PUNC">(</span><span class="STRN">'bidichecker.Revision'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 26</span> 
<span class='linenumber'> 27</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.Error'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 28</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.Filter'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 29</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.FilterFactory'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 30</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.TextErrorScanner'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 31</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.gui.server.GuiContainerFactory'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 32</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'bidichecker.gui.server.GuiServer'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 33</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'goog.array'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 34</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'goog.i18n.bidi'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 35</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'goog.json'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 36</span> </span><span class="NAME">goog.require</span><span class="PUNC">(</span><span class="STRN">'goog.userAgent.product'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 37</span> 
<span class='linenumber'> 38</span> 
<span class='linenumber'> 39</span> </span><span class="COMM">/**
<span class='linenumber'> 40</span>  * A class representing a revision of the BidiChecker checks. Higher revisions
<span class='linenumber'> 41</span>  * indicate later releases, which check for more error situations.
<span class='linenumber'> 42</span>  * @param {number} revision The revision number.
<span class='linenumber'> 43</span>  * @constructor
<span class='linenumber'> 44</span>  */</span><span class="WHIT">
<span class='linenumber'> 45</span> </span><span class="NAME">bidichecker.Revision</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">revision</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'> 46</span>   </span><span class="COMM">/**
<span class='linenumber'> 47</span>    * @type {number}
<span class='linenumber'> 48</span>    */</span><span class="WHIT">
<span class='linenumber'> 49</span>   </span><span class="NAME">this.revision</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">revision</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 50</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 51</span> 
<span class='linenumber'> 52</span> 
<span class='linenumber'> 53</span> </span><span class="COMM">/**
<span class='linenumber'> 54</span>  * Currently the default revision, for backwards-compatibility with existing
<span class='linenumber'> 55</span>  * user tests that did not specify an explicit revision. Includes checks for
<span class='linenumber'> 56</span>  * overall page directionality, undeclared opposite-directionality inline text,
<span class='linenumber'> 57</span>  * and "spillover" which causes garbling of numbers following declared opposite-
<span class='linenumber'> 58</span>  * directionality text.
<span class='linenumber'> 59</span>  * &lt;p>This revision is no longer recommended and will be deprecated. Tests
<span class='linenumber'> 60</span>  * should use <code>REVISION_2</code>.
<span class='linenumber'> 61</span>  * @type {!bidichecker.Revision}
<span class='linenumber'> 62</span>  * @export
<span class='linenumber'> 63</span>  */</span><span class="WHIT">
<span class='linenumber'> 64</span> </span><span class="NAME">bidichecker.REVISION_1</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.Revision</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 65</span> 
<span class='linenumber'> 66</span> 
<span class='linenumber'> 67</span> </span><span class="COMM">/**
<span class='linenumber'> 68</span>  * Currently the latest revision. Adds checks for undeclared opposite-
<span class='linenumber'> 69</span>  * directionality text attributes such as input values and tooltip text.
<span class='linenumber'> 70</span>  * @type {!bidichecker.Revision}
<span class='linenumber'> 71</span>  * @export
<span class='linenumber'> 72</span>  */</span><span class="WHIT">
<span class='linenumber'> 73</span> </span><span class="NAME">bidichecker.REVISION_2</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.Revision</span><span class="PUNC">(</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 74</span> 
<span class='linenumber'> 75</span> 
<span class='linenumber'> 76</span> </span><span class="COMM">/**
<span class='linenumber'> 77</span>  * Always points to the latest revision. Automated tests should avoid using
<span class='linenumber'> 78</span>  * this, as it means that newly-added checks will cause the automated tests to
<span class='linenumber'> 79</span>  * fail.
<span class='linenumber'> 80</span>  * @type {!bidichecker.Revision}
<span class='linenumber'> 81</span>  * @export
<span class='linenumber'> 82</span>  */</span><span class="WHIT">
<span class='linenumber'> 83</span> </span><span class="NAME">bidichecker.LATEST</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">bidichecker.REVISION_2</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 84</span> 
<span class='linenumber'> 85</span> 
<span class='linenumber'> 86</span> 
<span class='linenumber'> 87</span> 
<span class='linenumber'> 88</span> </span><span class="COMM">/**
<span class='linenumber'> 89</span>  * Entry point of the GUI web application.
<span class='linenumber'> 90</span>  * @const
<span class='linenumber'> 91</span>  * @type {string}
<span class='linenumber'> 92</span>  * @private
<span class='linenumber'> 93</span>  */</span><span class="WHIT">
<span class='linenumber'> 94</span> </span><span class="NAME">bidichecker.GUI_APP_URL_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'> 95</span>     </span><span class="STRN">'https://bidichecker.googlecode.com/svn/trunk/lib/gui-app/errorpage.html'</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'> 96</span> 
<span class='linenumber'> 97</span> 
<span class='linenumber'> 98</span> </span><span class="COMM">/**
<span class='linenumber'> 99</span>  * Default location of the precompiled bidichecker package.
<span class='linenumber'>100</span>  * @const
<span class='linenumber'>101</span>  * @type {string}
<span class='linenumber'>102</span>  * @private
<span class='linenumber'>103</span>  */</span><span class="WHIT">
<span class='linenumber'>104</span> </span><span class="NAME">bidichecker.PACKAGE_URL_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>105</span>     </span><span class="STRN">'https://bidichecker.googlecode.com/svn/trunk/lib/bidichecker_packaged.js'</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>106</span> 
<span class='linenumber'>107</span> 
<span class='linenumber'>108</span> </span><span class="COMM">/**
<span class='linenumber'>109</span>  * Class which checks a web page for bidi-related errors. The preferred way to
<span class='linenumber'>110</span>  * invoke BidiChecker is by constructing an instance of this class. The previous
<span class='linenumber'>111</span>  * API, based on static methods, is no longer recommended and will be
<span class='linenumber'>112</span>  * deprecated.
<span class='linenumber'>113</span>  * @param {!bidichecker.Revision} revision Revision of BidiChecker checks to
<span class='linenumber'>114</span>  *     run.
<span class='linenumber'>115</span>  * @export
<span class='linenumber'>116</span>  * @constructor
<span class='linenumber'>117</span>  */</span><span class="WHIT">
<span class='linenumber'>118</span> </span><span class="NAME">bidichecker.BidiChecker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">revision</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>119</span>   </span><span class="COMM">/**
<span class='linenumber'>120</span>    * @type {!bidichecker.Revision}
<span class='linenumber'>121</span>    * @private
<span class='linenumber'>122</span>    */</span><span class="WHIT">
<span class='linenumber'>123</span>   </span><span class="NAME">this.revision_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">revision</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>124</span> 
<span class='linenumber'>125</span>   </span><span class="COMM">/**
<span class='linenumber'>126</span>    * The errors reported by the last call to <code>checkPage()</code>.
<span class='linenumber'>127</span>    * @type {!Array.&lt;!bidichecker.Error>}
<span class='linenumber'>128</span>    * @private
<span class='linenumber'>129</span>    */</span><span class="WHIT">
<span class='linenumber'>130</span>   </span><span class="NAME">this.errors_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>131</span> 
<span class='linenumber'>132</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>133</span> 
<span class='linenumber'>134</span> 
<span class='linenumber'>135</span> </span><span class="COMM">/**
<span class='linenumber'>136</span>  * A static instance of BidiChecker, for use by an external interface.
<span class='linenumber'>137</span>  * @type {bidichecker.BidiChecker}
<span class='linenumber'>138</span>  * @export
<span class='linenumber'>139</span>  */</span><span class="WHIT">
<span class='linenumber'>140</span> </span><span class="NAME">bidichecker.instance</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>141</span> 
<span class='linenumber'>142</span> 
<span class='linenumber'>143</span> </span><span class="COMM">/**
<span class='linenumber'>144</span>  * Root path for the GUI application.
<span class='linenumber'>145</span>  * @type {string}
<span class='linenumber'>146</span>  * @private
<span class='linenumber'>147</span>  */</span><span class="WHIT">
<span class='linenumber'>148</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.guiAppUrl_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">bidichecker.GUI_APP_URL_</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>149</span> 
<span class='linenumber'>150</span> 
<span class='linenumber'>151</span> </span><span class="COMM">/**
<span class='linenumber'>152</span>  * Checks the contents of the current web page, including all nested frames, for
<span class='linenumber'>153</span>  * bidi-related errors. If <code>opt_element</code> is specified, checks only within
<span class='linenumber'>154</span>  * the given element of the DOM (including any nested frames).
<span class='linenumber'>155</span>  * @param {boolean} shouldBeRtl Is the root expected to be right-to-left?
<span class='linenumber'>156</span>  * @param {Element=} opt_element The root element of the DOM subtree to be
<span class='linenumber'>157</span>  *     checked; if null, checks the entire current web page.
<span class='linenumber'>158</span>  * @param {Array.&lt;!bidichecker.Filter>=} opt_filters Error suppression filters.
<span class='linenumber'>159</span>  * @return {!Array.&lt;!bidichecker.Error>} Array of error objects for all failing
<span class='linenumber'>160</span>  *     checks.
<span class='linenumber'>161</span>  * @export
<span class='linenumber'>162</span>  */</span><span class="WHIT">
<span class='linenumber'>163</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.checkPage</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">shouldBeRtl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_element</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>164</span>     </span><span class="NAME">opt_filters</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>165</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">expectedDir</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>166</span>       </span><span class="NAME">shouldBeRtl</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">goog.i18n.bidi.Dir.RTL</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">goog.i18n.bidi.Dir.LTR</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>167</span>   </span><span class="COMM">// {@top.document.body} always finds the top level of the current page, even</span><span class="WHIT">
<span class='linenumber'>168</span>   </span><span class="COMM">// if we started within a frame.</span><span class="WHIT">
<span class='linenumber'>169</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nonNullElement</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>170</span>       </span><span class="COMM">/** @type {!Element} */</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">opt_element</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">top.document.body</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>171</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">filters</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_filters</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>172</span> 
<span class='linenumber'>173</span>   </span><span class="NAME">bidichecker.Error.clearHighlightableAreas</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>174</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scanner</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>175</span>       </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.TextErrorScanner</span><span class="PUNC">(</span><span class="NAME">this.revision_.revision</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">filters</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>176</span>   </span><span class="NAME">scanner.scan</span><span class="PUNC">(</span><span class="NAME">nonNullElement</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">expectedDir</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>177</span>   </span><span class="NAME">this.errors_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">scanner.getErrors</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>178</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">goog.array.clone</span><span class="PUNC">(</span><span class="NAME">this.errors_</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>179</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>180</span> 
<span class='linenumber'>181</span> 
<span class='linenumber'>182</span> </span><span class="COMM">/**
<span class='linenumber'>183</span>  * JSON interface to <code>checkPage</code>.
<span class='linenumber'>184</span>  * @param {boolean} shouldBeRtl Is the element/page expected to be
<span class='linenumber'>185</span>  *     right-to-left?
<span class='linenumber'>186</span>  * @param {Element} element The root element of the DOM subtree to be checked;
<span class='linenumber'>187</span>  *     if null, checks the entire current web page.
<span class='linenumber'>188</span>  * @param {string} filtersJson Error suppression filters in a JSON string,
<span class='linenumber'>189</span>  *     representing a (possibly-empty) array of filter objects.
<span class='linenumber'>190</span>  * @return {string} Array of <code>bidichecker.Error</code> objects for all failing
<span class='linenumber'>191</span>  *     checks, in JSON format. If no errors were found, returns an empty array
<span class='linenumber'>192</span>  *     ("[]").
<span class='linenumber'>193</span>  * @export
<span class='linenumber'>194</span>  */</span><span class="WHIT">
<span class='linenumber'>195</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.checkPageToJson</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">shouldBeRtl</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>196</span>     </span><span class="NAME">element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">filtersJson</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>197</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">filters</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">bidichecker.FilterFactory.readFiltersFromJson</span><span class="PUNC">(</span><span class="NAME">filtersJson</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>198</span>   </span><span class="NAME">filters</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">filters</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="PUNC">[</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>199</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">errors</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this.checkPage</span><span class="PUNC">(</span><span class="NAME">shouldBeRtl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">filters</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>200</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">bidichecker.Error.serialize</span><span class="PUNC">(</span><span class="NAME">errors</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>201</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>202</span> 
<span class='linenumber'>203</span> 
<span class='linenumber'>204</span> </span><span class="COMM">/**
<span class='linenumber'>205</span>  * Sets the location of the GUI files.
<span class='linenumber'>206</span>  * @param {string} guiAppUrl Location of the GUI files.
<span class='linenumber'>207</span>  * @export
<span class='linenumber'>208</span>  */</span><span class="WHIT">
<span class='linenumber'>209</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.setGuiAppUrl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">guiAppUrl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>210</span>   </span><span class="NAME">this.guiAppUrl_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">guiAppUrl</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>211</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>212</span> 
<span class='linenumber'>213</span> 
<span class='linenumber'>214</span> </span><span class="COMM">/**
<span class='linenumber'>215</span>  * Runs the interactive visual error browsing GUI, displaying the errors
<span class='linenumber'>216</span>  * reported by the last call to <code>checkPage()</code>. Calling <code>runGui()</code>
<span class='linenumber'>217</span>  * before <code>checkPage()</code> is not supported (and is a no-op). If a GUI opened
<span class='linenumber'>218</span>  * by any prior BidiChecker call in this window is still open, it will be closed
<span class='linenumber'>219</span>  * and then re-opened.
<span class='linenumber'>220</span>  * On IE versions 8 and above, the GUI will always be displayed in an in-page
<span class='linenumber'>221</span>  * dialog box, regardless of the value of opt_noPopup.
<span class='linenumber'>222</span>  * On earlier versions of IE, the GUI will not be displayed. An error message
<span class='linenumber'>223</span>  * will be displayed instead.
<span class='linenumber'>224</span>  * @param {boolean=} opt_noPopup Disables opening the error browser in a popup
<span class='linenumber'>225</span>  *     window.
<span class='linenumber'>226</span>  * @export
<span class='linenumber'>227</span>  */</span><span class="WHIT">
<span class='linenumber'>228</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.runGui</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">opt_noPopup</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>229</span>   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">this.errors_.length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>230</span>     </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>231</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>232</span>   </span><span class="NAME">this.runGuiWithErrors_</span><span class="PUNC">(</span><span class="NAME">this.errors_</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_noPopup</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>233</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>234</span> 
<span class='linenumber'>235</span> 
<span class='linenumber'>236</span> </span><span class="COMM">/**
<span class='linenumber'>237</span>  * Runs the interactive visual error browsing GUI, displaying the given errors.
<span class='linenumber'>238</span>  * If a GUI opened by any prior BidiChecker call in this window is still open,
<span class='linenumber'>239</span>  * it will be closed and then re-opened.
<span class='linenumber'>240</span>  * On IE versions 8 and above, the GUI will always be displayed in an in-page
<span class='linenumber'>241</span>  * dialog box, regardless of the value of opt_noPopup.
<span class='linenumber'>242</span>  * On earlier versions of IE, the GUI will not be displayed. An error message
<span class='linenumber'>243</span>  * will be displayed instead.
<span class='linenumber'>244</span>  * @param {!Array.&lt;!bidichecker.Error>} errors Array of error objects to
<span class='linenumber'>245</span>  *     display.
<span class='linenumber'>246</span>  * @param {boolean=} opt_noPopup Disables opening the error browser in a popup
<span class='linenumber'>247</span>  *     window.
<span class='linenumber'>248</span>  * @private
<span class='linenumber'>249</span>  */</span><span class="WHIT">
<span class='linenumber'>250</span> </span><span class="NAME">bidichecker.BidiChecker.prototype.runGuiWithErrors_</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">errors</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>251</span>     </span><span class="NAME">opt_noPopup</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>252</span>   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">goog.userAgent.IE</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>253</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">goog.userAgent.isVersion</span><span class="PUNC">(</span><span class="STRN">'8'</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>254</span>       </span><span class="COMM">// IE version 8 and up, force dialog to be used.</span><span class="WHIT">
<span class='linenumber'>255</span>       </span><span class="NAME">opt_noPopup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>256</span>     </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>257</span>       </span><span class="COMM">// IE before version 8, display error and quit.</span><span class="WHIT">
<span class='linenumber'>258</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">guiContainer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>259</span>           </span><span class="NAME">bidichecker.gui.server.GuiContainerFactory.createFromScratch</span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>260</span>       </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">msg</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'Sorry, bidichecker GUI is not supported in Internet '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>261</span>           </span><span class="STRN">'Explorer before version 8.'</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>262</span>       </span><span class="NAME">guiContainer.getContentWindow</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">document.write</span><span class="PUNC">(</span><span class="NAME">msg</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>263</span>       </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>264</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>265</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>266</span> 
<span class='linenumber'>267</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">guiContainer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>268</span>       </span><span class="NAME">bidichecker.gui.server.GuiContainerFactory.createFromScratch</span><span class="PUNC">(</span><span class="NAME">opt_noPopup</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>269</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">server</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.gui.server.GuiServer</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">guiContainer</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>270</span>       </span><span class="NAME">this.guiAppUrl_</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">errors</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>271</span>   </span><span class="COMM">// This disposes of the last GuiServer created by BidiChecker for this window,</span><span class="WHIT">
<span class='linenumber'>272</span>   </span><span class="COMM">// which disposes of the GuiContainer created for it, which closes the GUI.</span><span class="WHIT">
<span class='linenumber'>273</span>   </span><span class="NAME">bidichecker.gui.server.GuiServer.startServer</span><span class="PUNC">(</span><span class="NAME">server</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>274</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>275</span> 
<span class='linenumber'>276</span> 
<span class='linenumber'>277</span> </span><span class="COMM">/**
<span class='linenumber'>278</span>  * Runs the bookmarklet GUI with a given set of initial options. If a GUI opened
<span class='linenumber'>279</span>  * by any prior BidiChecker call in this window is still open, it will be closed
<span class='linenumber'>280</span>  * and then re-opened.
<span class='linenumber'>281</span>  * On IE the given window is closed, and the GUI is opened in an in-page dialog.
<span class='linenumber'>282</span>  * (This is relevant only for IE versions 9 and up, as the bookmarklet doesn't
<span class='linenumber'>283</span>  * work on earlier versions of IE, due to URL length and other restrictions).
<span class='linenumber'>284</span>  * @param {Object.&lt;string, Object>} options The initial options.
<span class='linenumber'>285</span>  *     Options are specified as an object with the following (optional) keys:
<span class='linenumber'>286</span>  *     &lt;ul>
<span class='linenumber'>287</span>  *     &lt;li>dir -- string, "rtl" or "ltr" (the default). The expected page
<span class='linenumber'>288</span>  *     directionality.
<span class='linenumber'>289</span>  *     &lt;li>severity -- The severity level from which to suppress error messages,
<span class='linenumber'>290</span>  *     or -1 (for no severity filtering). Default 4.
<span class='linenumber'>291</span>  *     &lt;/ul>
<span class='linenumber'>292</span>  * @param {Window} hostWindow The underlying browser window object
<span class='linenumber'>293</span>  *     to be used by the GUI, as returned by window.open, or null to have the
<span class='linenumber'>294</span>  *     function open a new window itself. If non-null, the window should be
<span class='linenumber'>295</span>  *     empty. Do not pass null when calling this function in an onload handler
<span class='linenumber'>296</span>  *     because pop-up blockers will not let it open a window.
<span class='linenumber'>297</span>  * @param {string=} opt_guiAppUrl Location of the GUI files.
<span class='linenumber'>298</span>  * @export
<span class='linenumber'>299</span>  */</span><span class="WHIT">
<span class='linenumber'>300</span> </span><span class="NAME">bidichecker.runBookmarkletGui</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">hostWindow</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_guiAppUrl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>301</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">checker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.BidiChecker</span><span class="PUNC">(</span><span class="NAME">bidichecker.LATEST</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>302</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">guiContainer</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>303</span>   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">goog.userAgent.IE</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>304</span>     </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">hostWindow</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>305</span>       </span><span class="NAME">hostWindow.close</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>306</span>     </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>307</span>     </span><span class="NAME">guiContainer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>308</span>         </span><span class="NAME">bidichecker.gui.server.GuiContainerFactory.createFromScratch</span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>309</span>   </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>310</span>     </span><span class="NAME">guiContainer</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">
<span class='linenumber'>311</span>         </span><span class="NAME">bidichecker.gui.server.GuiContainerFactory.createFromWindow</span><span class="PUNC">(</span><span class="NAME">hostWindow</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>312</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>313</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">server</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.gui.server.GuiServer</span><span class="PUNC">(</span><span class="NAME">checker</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">options</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>314</span>       </span><span class="NAME">guiContainer</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_guiAppUrl</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">bidichecker.GUI_APP_URL_</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>315</span>   </span><span class="NAME">bidichecker.gui.server.GuiServer.startServer</span><span class="PUNC">(</span><span class="NAME">server</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>316</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>317</span> 
<span class='linenumber'>318</span> 
<span class='linenumber'>319</span> </span><span class="COMM">/**
<span class='linenumber'>320</span>  * Generates a BidiChecker bookmarklet. This is a javascript: url that loads the
<span class='linenumber'>321</span>  * BidiChecker package and activates the options page.
<span class='linenumber'>322</span>  * @param {!Object.&lt;string, !Object>} options The options that the options page
<span class='linenumber'>323</span>  *     will be initially populated with. See OptionsPage constructor
<span class='linenumber'>324</span>  *     documentation for more information.
<span class='linenumber'>325</span>  * @param {string=} opt_scriptUrl Location of the BidiChecker package. Used to
<span class='linenumber'>326</span>  *     install the GUI server. Must not include characters that have special
<span class='linenumber'>327</span>  *     meaning inside JavaScript strings.
<span class='linenumber'>328</span>  * @param {string=} opt_guiAppUrl Location of the GUI application. Must not
<span class='linenumber'>329</span>  *     include characters that have special meaning inside JavaScript strings.
<span class='linenumber'>330</span>  * @return {string} The generated link.
<span class='linenumber'>331</span>  * @export
<span class='linenumber'>332</span>  */</span><span class="WHIT">
<span class='linenumber'>333</span> </span><span class="NAME">bidichecker.generateBookmarklet</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_scriptUrl</span><span class="PUNC">,</span><span class="WHIT">
<span class='linenumber'>334</span>     </span><span class="NAME">opt_guiAppUrl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>335</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">scriptUrl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_scriptUrl</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">bidichecker.PACKAGE_URL_</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>336</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">guiAppUrl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">opt_guiAppUrl</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">bidichecker.GUI_APP_URL_</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>337</span> 
<span class='linenumber'>338</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">template</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'javascript:'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>339</span>     </span><span class="STRN">'(function() {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>340</span>       </span><span class="STRN">'function run() {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>341</span>         </span><span class="STRN">'bidichecker.runBookmarkletGui(%OPTIONS%, '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>342</span>             </span><span class="STRN">'g_bidicheckerBookmarkletGuiWnd, "%APPURL%");'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>343</span>       </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>344</span>       </span><span class="COMM">// The window object for the last opened window. Make sure the variable is</span><span class="WHIT">
<span class='linenumber'>345</span>       </span><span class="COMM">// defined.</span><span class="WHIT">
<span class='linenumber'>346</span>       </span><span class="STRN">'if (typeof g_bidicheckerBookmarkletGuiWnd == "undefined") {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>347</span>         </span><span class="STRN">'g_bidicheckerBookmarkletGuiWnd = null;'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>348</span>       </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>349</span>       </span><span class="STRN">'if (g_bidicheckerBookmarkletGuiWnd &&'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>350</span>           </span><span class="STRN">'!g_bidicheckerBookmarkletGuiWnd.closed) {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>351</span>         </span><span class="COMM">// If the window is already open, there's nothing more for us to do.</span><span class="WHIT">
<span class='linenumber'>352</span>         </span><span class="STRN">'g_bidicheckerBookmarkletGuiWnd.focus();'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>353</span>       </span><span class="STRN">'} else {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>354</span>         </span><span class="COMM">// Open a new window. Must be done as an immediate result of the</span><span class="WHIT">
<span class='linenumber'>355</span>         </span><span class="COMM">// bookmarklet being activated, not in the onload event; otherwise it</span><span class="WHIT">
<span class='linenumber'>356</span>         </span><span class="COMM">// may be blocked by the popup blocker.</span><span class="WHIT">
<span class='linenumber'>357</span>         </span><span class="STRN">'g_bidicheckerBookmarkletGuiWnd = window.open("about:blank", '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>358</span>           </span><span class="STRN">'"_blank", "width=1,height=1,resizable=yes,scrollbars=yes");'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>359</span>         </span><span class="COMM">// ID of the element used to hold the script.</span><span class="WHIT">
<span class='linenumber'>360</span>         </span><span class="STRN">'var scriptElemId = "_bidichecker_bookmarklet";'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>361</span>         </span><span class="COMM">// Load the script if we haven't done so already.</span><span class="WHIT">
<span class='linenumber'>362</span>         </span><span class="STRN">'if (document.getElementById(scriptElemId)) {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>363</span>           </span><span class="COMM">// Script element already exists. It doesn't mean that the script has</span><span class="WHIT">
<span class='linenumber'>364</span>           </span><span class="COMM">// been loaded yet, though, so check that bidichecker exists before</span><span class="WHIT">
<span class='linenumber'>365</span>           </span><span class="COMM">// proceeding. (We could probably just go ahead without checking, as</span><span class="WHIT">
<span class='linenumber'>366</span>           </span><span class="COMM">// normally JavaScript errors are silently ignored, but the page may</span><span class="WHIT">
<span class='linenumber'>367</span>           </span><span class="COMM">// have installed an error handler.)</span><span class="WHIT">
<span class='linenumber'>368</span>           </span><span class="STRN">'if (window.bidichecker) {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>369</span>             </span><span class="STRN">'run();'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>370</span>           </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>371</span>         </span><span class="STRN">'} else {'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>372</span>           </span><span class="COMM">// Add script to document and call it when it's loaded.</span><span class="WHIT">
<span class='linenumber'>373</span>           </span><span class="STRN">'var elem = document.createElement("script");'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>374</span>           </span><span class="STRN">'elem.src = "%SCRIPTURL%";'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>375</span>           </span><span class="STRN">'elem.onload = run;'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>376</span>           </span><span class="STRN">'elem.id = scriptElemId;'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>377</span>           </span><span class="STRN">'document.getElementsByTagName("head")[0].appendChild(elem);'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>378</span>         </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>379</span>       </span><span class="STRN">'}'</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT">
<span class='linenumber'>380</span>     </span><span class="STRN">'})()'</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>381</span> 
<span class='linenumber'>382</span>   </span><span class="COMM">// Substitute actual values in template. "$" is a meta character in the</span><span class="WHIT">
<span class='linenumber'>383</span>   </span><span class="COMM">// replace() method, so we need to escape it.</span><span class="WHIT">
<span class='linenumber'>384</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">optionsStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">goog.json.serialize</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="REGX">/\$/g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'$$$$'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>385</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">template.replace</span><span class="PUNC">(</span><span class="STRN">'%SCRIPTURL%'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">scriptUrl</span><span class="PUNC">)</span><span class="WHIT">
<span class='linenumber'>386</span>       </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'%APPURL%'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">guiAppUrl</span><span class="PUNC">)</span><span class="WHIT">
<span class='linenumber'>387</span>       </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'%OPTIONS%'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">optionsStr</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>388</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>389</span> 
<span class='linenumber'>390</span> 
<span class='linenumber'>391</span> </span><span class="COMM">/**
<span class='linenumber'>392</span>  * Checks the contents of the current web page, including all nested frames, for
<span class='linenumber'>393</span>  * bidi-related errors. If <code>opt_element</code> is specified, checks only within
<span class='linenumber'>394</span>  * the given element of the DOM (including any nested frames).
<span class='linenumber'>395</span>  * &lt;p>This used to be the main entry point for the Javascript API. It is now
<span class='linenumber'>396</span>  * deprecated, and is here only for compatibility with any bookmarklets created
<span class='linenumber'>397</span>  * by users before the class-based API was introduced. All other code should
<span class='linenumber'>398</span>  * instead construct an instance of <code>bidichecker.BidiChecker</code> and call its
<span class='linenumber'>399</span>  * <code>checkPage()</code> instance method.
<span class='linenumber'>400</span>  * @param {boolean} shouldBeRtl Is the root expected to be right-to-left?
<span class='linenumber'>401</span>  * @param {Element=} opt_element The root element of the DOM subtree to be
<span class='linenumber'>402</span>  *     checked; if null, checks the entire current web page.
<span class='linenumber'>403</span>  * @param {Array.&lt;!bidichecker.Filter>=} opt_filters Error suppression filters.
<span class='linenumber'>404</span>  * @return {!Array.&lt;!bidichecker.Error>} Array of error objects for all failing
<span class='linenumber'>405</span>  *     checks.
<span class='linenumber'>406</span>  * @export
<span class='linenumber'>407</span>  * @deprecated Use the checkPage() instance method of the BidiChecker class.
<span class='linenumber'>408</span>  */</span><span class="WHIT">
<span class='linenumber'>409</span> </span><span class="NAME">bidichecker.checkPage</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">shouldBeRtl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_filters</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>410</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">checker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.BidiChecker</span><span class="PUNC">(</span><span class="NAME">bidichecker.LATEST</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>411</span>   </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">checker.checkPage</span><span class="PUNC">(</span><span class="NAME">shouldBeRtl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_element</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_filters</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>412</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>413</span> 
<span class='linenumber'>414</span> 
<span class='linenumber'>415</span> </span><span class="COMM">/**
<span class='linenumber'>416</span>  * Runs the interactive visual error browsing GUI. If a GUI opened by any prior
<span class='linenumber'>417</span>  * BidiChecker call in this window is still open, it will be closed and then
<span class='linenumber'>418</span>  * re-opened.
<span class='linenumber'>419</span>  * &lt;p>This entry point is deprecated, and is here only for compatibility with
<span class='linenumber'>420</span>  * any bookmarklets created by users before the class-based API was introduced.
<span class='linenumber'>421</span>  * All other code should instead construct an instance of
<span class='linenumber'>422</span>  * <code>bidichecker.BidiChecker</code> and call its <code>checkPage()</code> and
<span class='linenumber'>423</span>  * <code>runGui()</code> instance methods.
<span class='linenumber'>424</span>  * @param {!Array.&lt;!bidichecker.Error>} errors An array of errors to be
<span class='linenumber'>425</span>  *     displayed.
<span class='linenumber'>426</span>  * @param {boolean=} opt_noPopup Disables opening the error browser in a popup
<span class='linenumber'>427</span>  *     window.
<span class='linenumber'>428</span>  * @param {string=} opt_guiAppUrl Location of the GUI files.
<span class='linenumber'>429</span>  * @export
<span class='linenumber'>430</span>  * @deprecated Use the runGui() instance method of the BidiChecker class.
<span class='linenumber'>431</span>  */</span><span class="WHIT">
<span class='linenumber'>432</span> </span><span class="NAME">bidichecker.runGui</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">errors</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_noPopup</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_guiAppUrl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>433</span>   </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">checker</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">bidichecker.BidiChecker</span><span class="PUNC">(</span><span class="NAME">bidichecker.LATEST</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>434</span>   </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">opt_guiAppUrl</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='linenumber'>435</span>     </span><span class="NAME">checker.setGuiAppUrl</span><span class="PUNC">(</span><span class="NAME">opt_guiAppUrl</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>436</span>   </span><span class="PUNC">}</span><span class="WHIT">
<span class='linenumber'>437</span>   </span><span class="NAME">checker.runGuiWithErrors_</span><span class="PUNC">(</span><span class="NAME">errors</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">opt_noPopup</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>438</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='linenumber'>439</span> </span></pre></body></html>